/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package phd.dupenois.changeidentifiers.dotpatterns.properties;

import java.util.HashMap;
//import java.util.Vector;

/**
 *
 * @author mpd209
 */
public class PropertiesHolder {

    private class Property{
        private Object object;
        private String key;
//        private boolean temporal;
//        public Property(String key, Object object, boolean temporal){
        public Property(String key, Object object){
            this.key = key;
            this.object = object;
//            this.temporal = temporal;
        }
        public Object getValue(){
            return object;
        }
        public String getkey(){
            return key;
        }
        public Class getValueClass(){
            return object.getClass();
        }

        /**
         * @return the temporal
         */
//        public boolean isTemporal() {
//            return temporal;
//        }
    }
    private  HashMap<String, Property> mapping;
//    private Vector<String> removable;

    public PropertiesHolder(){
//         removable = new Vector<String>();
         mapping = new HashMap<String, Property>();
    }

    public boolean has(String key){
        return (mapping.containsKey(key));
    }


    public Class getPropertyClass(String key){
        if(!has(key)) return null;
        Property prop = mapping.get(key);
        return prop.getValueClass();
    }
    public <T> T get(String key, Class<T> thisClass) throws ClassCastException{
        if(!has(key)) return null;
        Property prop = mapping.get(key);
        return (T) prop.getValue();
    }
//    public void set(String key, Object object, boolean temporal){
//        Property prop = new Property(key, object, temporal);
    public void set(String key, Object object){
        Property prop = new Property(key, object);
        mapping.put(key, prop);
//        if(!temporal&&removable.contains(key)){
//            removable.remove(key);
//        }else if(temporal&&!removable.contains(key)){
//            removable.add(key);
//        }
    }

//    public void reset(){
//        for(String key : removable){
//            mapping.remove(key);
//        }
//        removable.clear();
//    }
    public void clear(){
        mapping.clear();
//        removable.clear();
    }

}
